const conf = require("../conf")
const mongoose = require("mongoose")

let url = `mongodb://${conf.mongo.host}:${conf.mongo.port}/${conf.mongo.db}`;
let options = {useNewUrlParser: true, useUnifiedTopology: true};

let connection = mongoose.connect(url, options).catch(e => {
    console.error(`catch an err:\n${e.toString()}`)
    process.exit()
});

module.exports = {
    async connect(ctx){
        return await connection
    }
};